import { defineStore } from 'pinia';
import { ref, computed } from 'vue';

export const useTestStore = defineStore('test', () => {
  // 响应式对象，对应于 state
  const id = ref<number>(1001);
  const familyName = ref<string>('zhang');
  const name = ref<string>('san');

  // 对应于 getter
  const getFullName = computed(() => {
    return familyName.value + '-' + name.value;
  });

  // 对应于 action
  function updateName(nameVal: string) {
    name.value = nameVal;
  }
  function updateFamilyName(familyNameVal: string) {
    familyName.value = familyNameVal;
  }

  return { id, familyName, name, getFullName, updateName, updateFamilyName };
});
